/**
 * @file rank/popularize/luogu1060/main.cpp
 * @brief
 * @see
 * @author Ruiming Guo (guoruiming@stu.scu.edu.cn)
 * @copyright 2022
 * @date 2022/7/7 17:21:13
 **/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 30000 + 10, M = 30;
int dp[N];
int v[M], w[M];
int n, m;
int main() {
  // High rating and good luck!
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int val, p;
    cin >> val >> p;
    v[i] = val;
    w[i] = val * p;
  }

  for (int i = 0; i < m; ++i)
    for (int j = n; j >= 0; --j)
      if (j - v[i] >= 0) dp[j] = max(dp[j], dp[j - v[i]] + w[i]);
  cout << dp[n] << endl;
  return 0;
}
